import pymysql
from urlTestDemo.baseUrlTest import base_request_test
from urlTestDemo.redisUtils import initRedisUtils

redisUtil = initRedisUtils()
db_host = redisUtil.get("ship_db_host")
db_port = redisUtil.get("ship_db_port")
db_user = redisUtil.get("ship_db_user")
db_psw = redisUtil.get("ship_db_password")
db_name = redisUtil.get("ship_db_name")
pre_url = redisUtil.get("ship_pre_url")
search_sql = redisUtil.get("ship_search_sql")

conn = pymysql.connect(host=db_host, port=int(db_port), user=db_user, passwd=db_psw,db=db_name)
cur = conn.cursor()
cur.execute(search_sql)

def findAllOnlineShipProductUrl():
    shipPreUrl = pre_url
    priductIdList = []
    for row in cur.fetchall():
        id = row[0]
        priductIdList.append(shipPreUrl+str(id))
    cur.close()
    conn.close()
    return priductIdList

# 批量测试 邮轮组合产品链接
def batchTestShipUrl():
    allShipProblemUrlList = []  # 存放邮轮 问题url
    allOnlineShipUrls = findAllOnlineShipProductUrl()
    for shipProductUrl in allOnlineShipUrls:
        base_request_test(shipProductUrl,allShipProblemUrlList)
    print('邮轮问题链接列表',allShipProblemUrlList)
    return allShipProblemUrlList


